//
//  ZMYBookInfoViewController.m
//  奇阅
//
//  Created by 奇阅科技 on 14-11-5.
//  Copyright (c) 2014年 奇阅科技. All rights reserved.
//

#import "ZMYBookInfoViewController.h"
#import "ZMYBookInfoCollectionViewCell.h"
#import "ZMYBookInfoHeadCollectionReusableView.h"
#import "Config.h"
#import "BookThemeCommentListViewController.h"
#import "ZMYCatalogueTableViewController.h"
#import "ZMYReadViewController.h"
#import "BookrackCollectionViewController.h"
#import "MBProgressHUD.h"
#import "SIDownloadManager.h"
#import "SIBreakpointsDownload.h"
#import "GuidePageView.h"
#import "YiDongSubscription.h"
@interface ZMYBookInfoViewController ()
{
    BookInfo *bookInfo;
    CGSize strSize;
}
@property (weak, nonatomic) IBOutlet UIView *themeCommentListView;
@property (weak, nonatomic) IBOutlet UIView *topView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topViewTopConstraint;
@property (weak, nonatomic) IBOutlet UIButton *bookRackButton;
@property (nonatomic,assign)BOOL showAll;
@property (nonatomic,strong)NSArray *recommendedArray;
@end

@implementation ZMYBookInfoViewController
-(void)dealloc{
    NSLog(@"书籍详情页释放了");
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBarHidden = NO;
    [self setBarBackgroundImage:@"BookInfoNavBar"];
    [self setTitleForNavigation:@"书籍详情"];
    [self setLeftBackButtonForNavigation];
    [self setRightButtonForNavigation:@"bookRackButton" selector:@selector(toBookRack)];
    self.bookTitleLabel.text = self.book.title;
    [self.bookCoverImageView setImageWithURL:[NSURL URLWithString:self.book.imagefname] placeholderImage:[UIImage imageNamed:@"defaultCover"]];
    [self.bookCoverImageView addImageFullViewAnimation];
    self.themeCommentListView.hidden = YES;
    [self initData];
    [self showAnotherRecommended];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setBarBackgroundImage:@"BookInfoNavBar"];
    if (self.navigationController.navigationBarHidden) {
        [self.navigationController setNavigationBarHidden:NO animated:YES];
    }
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"bookInfoGuide"]) {
        GuidePageView *guideView = [[GuidePageView alloc]initWithGuideImage:[UIImage imageNamed:@"bookInfoGuide"]];
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"bookInfoGuide"];
        [guideView showView];
    }
}
-(void)toBookRack{
    if ([self frostedBookrackViewController]) {
        [self.navigationController popToViewController:[self frostedBookrackViewController] animated:YES];
    }else if ([self frostedViewController]) {
        [self.navigationController popToRootViewControllerAnimated:YES];
        [[self frostedViewController]hideSideViewController:YES];
    }else{
        [[AppDelegate delegate]goToBookRack];
    }
}
- (ZMYRootViewController *)frostedViewController
{
    UIViewController *iter = self.parentViewController;
    while (iter) {
        if ([iter isKindOfClass:[ZMYRootViewController class]]) {
            return (ZMYRootViewController *)iter;
        } else if (iter.parentViewController && iter.parentViewController != iter) {
            iter = iter.parentViewController;
        } else {
            iter = nil;
        }
    }
    return nil;
}
- (BookrackCollectionViewController *)frostedBookrackViewController
{
    for (UIViewController *iter in self.navigationController.viewControllers) {
        if ([iter isKindOfClass:[BookrackCollectionViewController class]]) {
            return (BookrackCollectionViewController *)iter;
        }
    }
    return nil;
}

-(void)initData{
    bookInfo = [[ZMYLKDB getLKDBHelper]getBookInfo:self.book.articleid];
    if (bookInfo) {
        [self setBookInfo];
        [self.articleCollectionView reloadData];
    }
    [self.navigationController setSGProgressPercentage:80 andTintColor:YellowColor];
    [[ZMYNetWorkAPI default] getArticle:self.book.articleid Response:^(NSDictionary *resultDic) {
        [self.navigationController setSGProgressPercentage:100 andTintColor:YellowColor];
        bookInfo = [[ZMYLKDB getLKDBHelper]getBookInfo:self.book.articleid];
        if (bookInfo) {
            [self setBookInfo];
        }
        [self.articleCollectionView reloadData];
    } error:^(NSString *errorStr) {
        [self.navigationController cancelSGProgress];
    }];
}

-(void)setBookInfo{
    self.book = bookInfo.book;
    self.bookTitleLabel.text = bookInfo.book.title;
    self.authorLabel.text = [NSString stringWithFormat:@"作者：%@",bookInfo.book.author];
    self.priceLabel.text = [NSString stringWithFormat:@"价格：%@阅币/千字",bookInfo.price];
    self.sortLabel.text = [NSString stringWithFormat:@"分类：%@",bookInfo.sortname];
    self.finishLabel.text = [NSString stringWithFormat:@"状态：%@",bookInfo.finishflag?@"已完结":@"连载中"];
    if ([[ZMYLKDB getLKDBHelper]getBookRack:self.book]) {
        [self.bookRackButton setBackgroundImage:[UIImage imageNamed:@"hadInRack"] forState:UIControlStateNormal];
        self.bookRackButton.enabled = NO;
    }else{
        [self.bookRackButton setBackgroundImage:[UIImage imageNamed:@"addRackButton"] forState:UIControlStateNormal];
        self.bookRackButton.enabled = YES;
    }
    if ([bookInfo.articleid hasPrefix:@"qiyou"]) {
        self.favoritesButton.hidden = YES;
    } else {
        if (bookInfo.isFavorites) {
            [self.favoritesButton setImage:[UIImage imageNamed:@"favoritesB"] forState:UIControlStateNormal];
        } else {
            [self.favoritesButton setImage:[UIImage imageNamed:@"favoritesA"] forState:UIControlStateNormal];
        }
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - 收藏按钮点击
- (IBAction)favoritesTheBook:(id)sender {
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        [AppDelegate showHUDAndHide:@"收藏只有登录才能使用，请先登录" view:self.view];
    } else {
        if (bookInfo) {
            if (bookInfo.isFavorites) {
                
                [[ZMYNetWorkAPI default] removeMyFavorArticleid:bookInfo.articleid response:^(NSDictionary *resultDic) {
                    
                } error:^(NSString *errorStr) {
                    
                }];
                MyFavorBook *favBook = [MyFavorBook new];
                favBook.uid = user.uid;
                favBook.articleid = bookInfo.articleid;
                favBook.book = bookInfo.book;
                favBook.wordtotal = bookInfo.wordtotal;
                favBook.lastUpdateInfo = bookInfo.last_chapter;
                favBook.finishflag = bookInfo.finishflag;
                [[ZMYLKDB getLKDBHelper] deleteMyFavorBook:favBook];
                [self.favoritesButton setImage:[UIImage imageNamed:@"favoritesA"] forState:UIControlStateNormal];
                bookInfo.isFavorites = NO;
            } else {
                [[ZMYNetWorkAPI default] addMyFavorArticleid:bookInfo.articleid response:^(NSDictionary *resultDic) {
                    
                } error:^(NSString *errorStr) {
                    
                }];
                MyFavorBook *favBook = [MyFavorBook new];
                favBook.uid = user.uid;
                favBook.articleid = bookInfo.articleid;
                favBook.book = bookInfo.book;
                favBook.wordtotal = bookInfo.wordtotal;
                favBook.lastUpdateInfo = bookInfo.last_chapter;
                favBook.finishflag = bookInfo.finishflag;
                [[ZMYLKDB getLKDBHelper] updateMyFavorBook:favBook];
                [self.favoritesButton setImage:[UIImage imageNamed:@"favoritesB"] forState:UIControlStateNormal];
                bookInfo.isFavorites = YES;
            }
        }else{
            [AppDelegate showHUDAndHide:@"正在获取网络数据，请稍后再试" view:self.view];
        }
    }
}

#pragma mark - 简介按钮点击
- (IBAction)descriptionClick:(id)sender {
    //将自己置为不可点击，将书评按钮置为可点击,并将试图返回下移
    self.articleButton.enabled = NO;
    self.commentButton.enabled = YES;
    self.topViewTopConstraint.constant = 0;
    [UIView animateWithDuration:0.3 animations:^{
        self.topViewTopConstraint.constant = 0;
        [self.view layoutSubviews];
    } completion:^(BOOL finished) {
        
    }];
    self.themeCommentListView.hidden = YES;
    self.articleCollectionView.hidden = NO;
}
#pragma mark - 书评按钮点击
- (IBAction)commentClick:(id)sender {
    //将自己置为不可点击，将书评按钮置为可点击，并将试图上移
    self.commentButton.enabled = NO;
    self.articleButton.enabled = YES;
    [UIView animateWithDuration:0.3 animations:^{
        self.topViewTopConstraint.constant = -self.topView.bounds.size.height;
        [self.view layoutSubviews];
    } completion:^(BOOL finished) {
//        [self.themeCommentListView.commentTableView reloadData];
    }];
    self.articleCollectionView.hidden = YES;
    self.themeCommentListView.hidden = NO;
}

#pragma mark - <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (bookInfo) {
        return 3;
    }
    return 0;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    ZMYBookInfoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZMYBookInfoCollectionViewCell" forIndexPath:indexPath];
    NSDictionary *dict = self.recommendedArray[indexPath.row];
    cell.bookTitleLabel.text = dict[@"title"];
    [cell.coverImageView setImageWithURL:[NSURL URLWithString:dict[@"coverpic"]] placeholderImage:[UIImage imageNamed:@"defaultCover"]];
    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    float width = (self.view.bounds.size.width-65)/3;
    return CGSizeMake(width, width*1.4+15);
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    if (!bookInfo) {
        return CGSizeZero;
    }
    strSize = [bookInfo.bookAbout boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-20, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} context:nil].size;
    if (self.showAll) {
        return CGSizeMake(self.view.bounds.size.width, strSize.height+72);
    }
    if (strSize.height>60) {
        return CGSizeMake(self.view.bounds.size.width, 60+72);
    }else{
        return CGSizeMake(self.view.bounds.size.width, strSize.height+72);
    }
}

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if ([kind isEqualToString: UICollectionElementKindSectionHeader]) {
        ZMYBookInfoHeadCollectionReusableView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ZMYBookInfoHeadCollectionReusableView" forIndexPath:indexPath];
        headView.aboutLabel.text = bookInfo.bookAbout;
        if (bookInfo.finishflag) {
            headView.updateLineLabel.hidden = YES;
            headView.updateLabel.hidden = YES;
            headView.updateButton.hidden = YES;
        } else {
            headView.updateLineLabel.hidden = NO;
            headView.updateLabel.hidden = NO;
            headView.updateButton.hidden = NO;
            [headView.updateButton setTitle:bookInfo.last_chapter forState:UIControlStateNormal];
        }
        __weak typeof(self) weakSelf = self;
        [headView showAll:^{
            weakSelf.showAll = YES;
            [weakSelf.articleCollectionView reloadData];
        }];
        [headView showBookCatalogue:^{
#pragma mark 查看目录
            ZMYCatalogueTableViewController * child_1 = [[UIStoryboard storyboardWithName:@"BookRack" bundle:nil] instantiateViewControllerWithIdentifier:@"ZMYCatalogueTableViewController"];
            child_1.book = weakSelf.book;
            child_1.isPushByNav = YES;
            [weakSelf.navigationController pushViewController:child_1 animated:YES];
        }];
        [headView showAnotherRecommended:^{
            [weakSelf showAnotherRecommended];
        }];
        if (strSize.height>60) {
            if (weakSelf.showAll) {
                headView.showAllButton.hidden = YES;
            } else {
                headView.showAllButton.hidden = NO;
            }
        } else {
            headView.showAllButton.hidden = YES;
        }
        return headView;
    }
    return [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"ZMYBookInfoFootCollectionReusableView" forIndexPath:indexPath];;
}
#pragma mark 推荐位换一换
-(void)showAnotherRecommended{
    [[ZMYNetWorkAPI default]getBookInfoRecommend:^(NSArray *resultArray) {
        if (resultArray.count>=3) {
            self.recommendedArray = [NSArray arrayWithArray:resultArray];
            [self.articleCollectionView reloadData];
        }
    } error:^(NSString *errorStr) {
        
    }];
}
#pragma mark 推荐位图书详情
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (self.recommendedArray.count<3) {
        return;
    }
    NSDictionary *dict = self.recommendedArray[indexPath.row];
    Book *book = [Book new];
    book.articleid = dict[@"articleid"];
    book.title = dict[@"title"];
    book.imagefname = dict[@"coverpic"];
    ZMYBookInfoViewController *view = [self.storyboard instantiateViewControllerWithIdentifier:@"ZMYBookInfoViewController"];
    view.book = book;
    [self.navigationController pushViewController:view animated:YES];
}
#pragma mark - 加入书架
- (IBAction)addBookRack:(id)sender {
    BookRack *book = [BookRack new];
    UserAccount *user = [UserAccount currentAccount];
    if (user) {
        book.uid = user.uid;
    } else {
        book.uid = @"love";
    }
    book.articleid = self.book.articleid;
    book.book = self.book;
    book.wordtotal = bookInfo.wordtotal;
    [[ZMYLKDB getLKDBHelper]updateBookRack:book];
    [self.bookRackButton setBackgroundImage:[UIImage imageNamed:@"hadInRack"] forState:UIControlStateNormal];
    self.bookRackButton.enabled = NO;
}
#pragma mark - 免费试读
- (IBAction)freeRead:(id)sender{
        if ([[ZMYLKDB getLKDBHelper]getBookChapterTextWithArticleid:self.book.articleid]) {
            ZMYReadViewController *bookReadViewController = [[UIStoryboard storyboardWithName:@"BookRack" bundle:nil]instantiateViewControllerWithIdentifier:@"ZMYReadViewController"];
            bookReadViewController.book = self.book;
            bookReadViewController.image = self.bookCoverImageView.image;
            [self.navigationController pushViewController:bookReadViewController animated:YES];
        } else {
            //如果没有下载过章节，先去判断有没有章节列表
            __block NSMutableArray *chapterArray = [NSKeyedUnarchiver unarchiveObjectWithFile:[[PathHelper documentDirectoryPathWithName:@"db"]
                                                                                       stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ChapterInfo",self.book.articleid]]];
            __weak typeof(self) weakSlef = self;
            __block MBProgressHUD *progressHud = [MBProgressHUD showHUDAddedTo:[AppDelegate delegate].window animated:YES];
            progressHud.removeFromSuperViewOnHide = YES;
            progressHud.dimBackground = YES;
            progressHud.mode =MBProgressHUDModeDeterminate;
            progressHud.detailsLabelText = @"加载中...";
            [progressHud setProgress:0.1];
            progressHud.removeFromSuperViewOnHide=YES;
            
            if (!chapterArray) {
                //如果没有章节列表，先去请求章节列表
                [[ZMYNetWorkAPI default] getBookChapterBook:weakSlef.book Response:^(NSDictionary *resultDic) {
                    if ([weakSlef.book.articleid hasPrefix:@"qiyou"]) {
                        YiDongSubscription *subView = [[[NSBundle mainBundle]loadNibNamed:@"YiDongSubscription" owner:nil options:nil]lastObject];
                        chapterArray = [NSKeyedUnarchiver unarchiveObjectWithFile:[[PathHelper documentDirectoryPathWithName:@"db"]
                                                                                   stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ChapterInfo",weakSlef.book.articleid]]];
                        subView.chapterId = ((BookChapterInfo *)[chapterArray objectAtIndex:0]).chapterId;
                        subView.book= weakSlef.book;
                        [subView beginVerificationReadPermissionsSucceed:^{
                            ZMYReadViewController *bookReadViewController = [[UIStoryboard storyboardWithName:@"BookRack" bundle:nil]instantiateViewControllerWithIdentifier:@"ZMYReadViewController"];
                            bookReadViewController.book = weakSlef.book;
                            bookReadViewController.image = weakSlef.bookCoverImageView.image;
                            [self.navigationController pushViewController:bookReadViewController animated:YES];
                        } Fail:^{
                            progressHud.progress = 0;
                            [progressHud setHidden:YES];
                            [AppDelegate showHUDAndHide:@"章节下载失败" view:weakSlef.view];
                        } Cancel:^{
                            progressHud.progress = 0;
                            [progressHud setHidden:YES];
                            [AppDelegate showHUDAndHide:@"章节下载失败" view:weakSlef.view];
                        }];
                    } else {
                        progressHud.progress = 0.6;
                        //请求到章节列表后请求免费章节
                        [weakSlef downloadFreeChapter:self.book MBProgressHUD:progressHud];
                    }
                } error:^(NSString *errorStr) {
                    progressHud.progress = 0;
                    [progressHud setHidden:YES];
                    [AppDelegate showHUDAndHide:errorStr view:self.view];
                }];
            }else{
                if ([weakSlef.book.articleid hasPrefix:@"qiyou"]) {
                    YiDongSubscription *subView = [[[NSBundle mainBundle]loadNibNamed:@"YiDongSubscription" owner:nil options:nil]lastObject];
                    subView.chapterId = ((BookChapterInfo *)[chapterArray objectAtIndex:0]).chapterId;
                    subView.book= self.book;
                    [subView beginVerificationReadPermissionsSucceed:^{
                        ZMYReadViewController *bookReadViewController = [[UIStoryboard storyboardWithName:@"BookRack" bundle:nil]instantiateViewControllerWithIdentifier:@"ZMYReadViewController"];
                        bookReadViewController.book = weakSlef.book;
                        bookReadViewController.image = weakSlef.bookCoverImageView.image;
                        [self.navigationController pushViewController:bookReadViewController animated:YES];
                    } Fail:^{
                        progressHud.progress = 0;
                        [progressHud setHidden:YES];
                        [AppDelegate showHUDAndHide:@"章节下载失败" view:weakSlef.view];
                    } Cancel:^{
                        progressHud.progress = 0;
                        [progressHud setHidden:YES];
                        [AppDelegate showHUDAndHide:@"章节下载失败" view:weakSlef.view];
                    }];
                } else {
                    progressHud.progress = 0.6;
                    //如果有章节列表，直接去下载免费章节
                    [self downloadFreeChapter:self.book MBProgressHUD:progressHud];
                }
                
            }
            
        }

    
}
#pragma mark 断点下载免费章节内容
-(void)downloadFreeChapter:(Book *)book MBProgressHUD:(MBProgressHUD *)progressHud{
    __weak typeof(self) weakSlef = self;
    NSMutableArray *chapterArray = [NSKeyedUnarchiver unarchiveObjectWithFile:[[PathHelper documentDirectoryPathWithName:@"db"]
                                                                               stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ChapterInfo",book.articleid]]];
    NSMutableString *chapterIDs = [NSMutableString new];
    NSMutableArray *freeChapter = [NSMutableArray new];
    for (BookChapterInfo *chapterInfo in chapterArray) {
        if (![chapterInfo.is_vip isEqualToString:@"0"]) {
            break;
        }
        [freeChapter addObject:chapterInfo];
        if ([chapterArray indexOfObject:chapterInfo]==0) {
            [chapterIDs appendString:chapterInfo.chapterId];
        } else {
            [chapterIDs appendFormat:@",%@",chapterInfo.chapterId];
        }
        if (freeChapter.count>9) {
            break;
        }
    }
    if (freeChapter.count>0) {
        NSString *purviewMark = [[NSString stringWithFormat:@"%@%@",((BookChapterInfo *)[freeChapter objectAtIndex:0]).chapterId,((BookChapterInfo *)[freeChapter lastObject]).chapterId] md5];
        purviewMark = [[NSString stringWithFormat:@"qy_%@",purviewMark] md5];
        NSString *currentAppVersion = [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"];
        NSString *urlStr = [NSString stringWithFormat:@"http://%@/web/qy_book.php?a=download_articleid&purviewMark=%@&chapterids=%@&output=txt&ct=iOS&v=%@&srcid=iOS",SERVER,purviewMark,chapterIDs,currentAppVersion];
        NSString *downloadPath = [[PathHelper cacheDirectoryPathWithName:@"Lib"]stringByAppendingPathComponent:book.articleid];
        SIDownloadManager *siDownloadManager = [SIDownloadManager sharedSIDownloadManager];
        [siDownloadManager  addDownloadFileTaskInQueue:urlStr toFilePath:downloadPath breakpointResume:YES rewriteFile:NO DidComplete:^(SIDownloadManager *siDownloadManager, SIBreakpointsDownload *paramOperation) {
            if ([paramOperation.downloadFilePath isEqualToString:downloadPath]) {
                if ([[ZMYLKDB getLKDBHelper]unarchiveFreeChapter:downloadPath Book:book]) {
                    progressHud.progress = 1;
                    [progressHud setHidden:YES];
                    ZMYReadViewController *bookReadViewController = [[UIStoryboard storyboardWithName:@"BookRack" bundle:nil] instantiateViewControllerWithIdentifier:@"ZMYReadViewController"];
                    bookReadViewController.book = book;
                    bookReadViewController.image = weakSlef.bookCoverImageView.image;
                    [weakSlef.navigationController pushViewController:bookReadViewController animated:YES];
                    
                }else{
                    progressHud.progress = 1;
                    [progressHud setHidden:YES];
                    [AppDelegate showHUDAndHide:@"章节下载失败" view:weakSlef.view];
                }
            }
        } Progress:^(SIDownloadManager *siDownloadManager, SIBreakpointsDownload *paramOperation, double paramProgress) {
            if ([paramOperation.downloadFilePath isEqualToString:downloadPath]) {
                progressHud.progress = paramProgress*0.4+0.6;
            }
        } Error:^(SIDownloadManager *siDownloadManager, SIBreakpointsDownload *paramOperation, NSError *paramError) {
            if ([paramOperation.downloadFilePath isEqualToString:downloadPath]) {
                NSLog(@"%@ withError:%@",paramOperation.url,paramError.localizedDescription);
                progressHud.progress = 0;
                [progressHud setHidden:YES];
                [AppDelegate showHUDAndHide:paramError.localizedDescription view:weakSlef.view];
            }
            
        }];
    }
    
    
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString:@"myThemeCommentListView"]) {
        BookThemeCommentListViewController *viewController = [segue destinationViewController];
        viewController.book = self.book;
    }
}
@end
